package gsoc.ogsadai.model.diagram.edit.parts;

import gsoc.ogsadai.model.RequestType;
import gsoc.ogsadai.model.diagram.edit.policies.WorkflowTypeCanonicalEditPolicy;
import gsoc.ogsadai.model.diagram.edit.policies.WorkflowTypeItemSemanticEditPolicy;
import gsoc.ogsadai.model.properties.PropertiesPackage;
import gsoc.ogsadai.model.util.ModelResourceImpl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class WorkflowTypeEditPart extends DiagramEditPart {

	/**
	 * @generated
	 */
	public final static String MODEL_ID = "Request"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 79;

	/**
	 * @generated
	 */
	public WorkflowTypeEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new WorkflowTypeItemSemanticEditPolicy());
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
				new WorkflowTypeCanonicalEditPolicy());
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
	 */
	@Override
	protected void handleNotificationEvent(Notification event) {
		Object feature = event.getFeature();
		if (PropertiesPackage.eINSTANCE.getPropertiesStyle_ServerURL().equals(
				feature)) {

			EditingDomain editingDomain = getEditingDomain();
			ResourceSet resourceSet = editingDomain.getResourceSet();
			RequestType requestType = null;
			for (Resource resource : resourceSet.getResources()) {
				if (resource instanceof ModelResourceImpl) {
					for (TreeIterator<EObject> i = ((ModelResourceImpl) resource)
							.getAllContents(); i.hasNext();) {
						Object obj2 = i.next();
						if (obj2 instanceof RequestType) {
							requestType = ((RequestType) obj2);
							break;
						}
					}
				}
			}
			//	requestType.setStyleURI(EcoreUtil.getURI((EObject) feature).toString());

		}
		super.handleNotificationEvent(event);
	}

}
